<template>
	<view class="groupSetting">
		<view class="toggleGroupType">
			<text style="margin-right: 30rpx;" :class="{ active: isPaid }" @click="toggleGroupType(true)">付费群</text>
			<text :class="{ active: !isPaid }" @click="toggleGroupType(false)">免费群</text>
		</view>
		<view style="background-color: #fffaf5;
					padding: 10rpx;
					height: 75rpx;
					line-height: 75rpx;
					margin: 20rpx 0;
					color: #ff6600;
					border: 1px solid #ff6600;">
			<text>认证后即可使用群功能, 认证一下吧!</text>
		</view>
		<view v-if="isPaid">
			<h2>进群金额</h2>
			<view class="sponsorship" @click="toggleSponsorshipOptions">
				<text>{{ selectedSponsorship }}</text>
				<u-icon :name="icon"></u-icon>
			</view>
			<view v-if="showSponsorshipOptions" class="sponsorshipOptions">
				<text v-for="(option, index) in sponsorshipOptions" :key="index"
					:class="{ active: selectedSponsorship === option }"
					@click="selectSponsorship(option)">{{ option }}</text>
			</view>
		</view>
		<view>
			<h2>群名称</h2>
			<u--input border="bottom" placeholder='给你的群起个吸引人的名字吧' />
		</view>
		<view>
			<h2>群简介</h2>
			<u--textarea style="height: 240rpx;" placeholder='向大家介绍一下你的群吧...'></u--textarea>
		</view>
		<view>
			<h2>封面图</h2>
			<u-upload maxCount="1">
				<view class="uploadText">
					<text>更换封面图</text>
					<text>240x240以上</text>
				</view>
			</u-upload>

		</view>
		<view v-if="isPaid">
			<view style="display: flex; justify-content: space-between;align-items: center;">
				<text>任意发电累计金额达到多少即可进群</text>
				<u-switch activeColor="#ff6600" v-model="value2" @change="changes"></u-switch>
			</view>
		</view>
		<button style="background-color: #ff8c00;color: #fff;margin-top: 30rpx;">保存</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				icon: 'arrow-down-fill',
				value2: false,
				Sales: 2,
				isPaid: true, // 默认显示付费群
				showSponsorshipOptions: false, // 控制赞助选项显示
				selectedSponsorship: '所有赞助者', // 默认选中赞助选项
				sponsorshipOptions: ['所有赞助者', '￥15.00以上'], // 赞助选项数组
			}
		},
		methods: {
			toggleGroupType(isPaid) {
				this.isPaid = isPaid;
				if (!isPaid) {
					this.showSponsorshipOptions = false;
				}
			},
			toggleSponsorshipOptions() {
				this.showSponsorshipOptions = !this.showSponsorshipOptions;
			},
			selectSponsorship(option) {
				this.selectedSponsorship = option;
				this.showSponsorshipOptions = false;
			},
			changes(e) {
				if (e) {
					this.Sales = 1;
				} else {
					this.Sales = 2;
				}
			},
		}
	}
</script>

<style>
	.groupSetting {
		width: 90%;
		margin: auto;
		line-height: 110rpx;
	}

	.toggleGroupType text {
		display: inline-block;
		width: 45%;
		text-align: center;

		height: 90rpx;
		font-weight: 600;
		font-size: 38rpx;
		line-height: 90rpx;
		background-color: white;
		border: 1px solid transparent;
	}

	.toggleGroupType text.active {
		border: 1px solid #ff6600;
		/* 显示边框 */
	}

	h2 {
		font-size: 38rpx;
	}

	.sponsorship {
		display: flex;
		align-items: center;
		background-color: #fff;
		padding: 20rpx;
		height: 55rpx;
		color: #a2a2a2;
	}

	.sponsorship text {
		flex-grow: 1;
	}

	.sponsorshipOptions text {
		background-color: #fff;
		/* 未选中项背景色 */
		padding: 10rpx;
		height: 75rpx;
		line-height: 75rpx;
		display: block;
		padding-left: 20rpx;
		box-shadow: 0 4rpx 4rpx rgba(0, 0, 0, 0.1);
		/* 添加阴影效果 */
	}

	.sponsorshipOptions text.active {
		background-color: #eee;
		/* 选中项背景色 */
		font-weight: 600;
	}


	.uploadText {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: #e8e8e8;
		line-height: 45rpx;
		color: #666;
		height: 340rpx;
		width: 340rpx;
	}
</style>